package com.gxa.meiye.sso.controller;

import com.aliyuncs.exceptions.ClientException;
import com.gxa.meiye.core.common.JsonResult;
import com.gxa.meiye.sso.service.SmsService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Pattern;
import java.util.Map;

/**
 * @Author: zy
 * @CreateTime: 2022-07-19  20:49
 */
@RestController
@Api(value = "短信",tags = "短信接口")
@RequestMapping("/sso")
@Validated
public class SmsController {
    @Autowired
    private SmsService smsService;
    @PostMapping("/send")
    public Map Send(@RequestParam("phone")
                    @Pattern(regexp ="^[1](([3][0-9])|([4][5,7,9])|([5][0-9])|([6][6])|([7][3,5,6,7,8])|([8][0-9])|([9][8,9]))[0-9]{8}$" ,message = "手机号格式问题") String phone) throws ClientException {
        String s = smsService.smsSendLogin(phone);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setMsg("发送成功");
        jsonResult.setData(s);
        return jsonResult.getMap();

    }
}
